package com.it.service.impl;


import com.it.entity.ExamRecord;
import com.it.mapper.ExamRecordMapper;
import com.it.service.IExamRecordService;
import com.it.vo.ExamRecordVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;

/**
 * <p>
 *  考试记录实现类
 * </p>
 *
 * @author author
 * @since 2023-09-26
 */
@Service
public class ExamRecordServiceImpl implements IExamRecordService {
    @Resource
    ExamRecordMapper examRecordMapper;
    @Override
    public void addExamRecord(ExamRecord examRecord) {
      examRecordMapper.addExamRecord(examRecord);
    }

    @Override
    public List<ExamRecordVo> findExamRecordsByUserId(Long userId) {
        return examRecordMapper.getExamRecordsByUserId(userId);
    }

    @Override
    public Map<Date,Integer> findExamScoreByUserId(Long userId) {
        Map< Date,Integer> result = new TreeMap<>();
        List<ExamRecordVo> records = examRecordMapper.getExamRecordsByUserId(userId);
        records.forEach(rd -> result.put(rd.getCompleteTime(),rd.getScore()));
        return result;
    }
}
